﻿import request from '/@/utils/request';
import other from '/@/utils/other';
import {AxiosResponse} from 'axios';
import {ISysWechatUser, ISysWechatUserView, ISysWechatUserVm} from '/@/views/wechat/syswechatuser/api/interface';

interface ISysWechatUserApi {
  search(data: object): Promise<AxiosResponse<ISysWechatUserView[]>>;

  get(id: string | number): Promise<AxiosResponse<ISysWechatUserVm>>;

  add(data: ISysWechatUserVm): Promise<AxiosResponse<ISysWechatUser>>;

  edit(data: ISysWechatUserVm): Promise<AxiosResponse<ISysWechatUser>>;

  batchEdit(data: object): Promise<AxiosResponse>;

  delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;

  export(data: object): Promise<void>;

  exportById(ids: (string | number)[]): Promise<void>;

  import(data: object): Promise<AxiosResponse<number>>;

  batchUnbind(ids: (string | number)[]): Promise<AxiosResponse>;

  deleteUnboundUsers(): Promise<AxiosResponse<ISysWechatUserVm>>;
}

function SysWechatUserApi(): ISysWechatUserApi {
  return {
    async search(data: object): Promise<AxiosResponse<ISysWechatUserView[]>> {
      return await request({
        url: '/api/SysWechatUser/Search',
        method: 'post',
        data,
      });
    },
    async get(id: string | number): Promise<AxiosResponse<ISysWechatUserVm>> {
      return await request({
        url: `/api/SysWechatUser/${id}`,
        method: 'get',
      });
    },
    async add(data: ISysWechatUserVm): Promise<AxiosResponse<ISysWechatUser>> {
      return await request({
        url: '/api/SysWechatUser/Add',
        method: 'post',
        data,
      });
    },
    async edit(data: ISysWechatUserVm): Promise<AxiosResponse<ISysWechatUser>> {
      return await request({
        url: '/api/SysWechatUser/Edit',
        method: 'put',
        data,
      });
    },
    async batchEdit(data: object): Promise<AxiosResponse> {
      return await request({
        url: '/api/SysWechatUser/batchEdit',
        method: 'post',
        data,
      });
    },
    async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysWechatUser/BatchDelete',
        method: 'post',
        data: ids,
      });
    },
    async export(data: object): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysWechatUser/ExportExcel',
        method: 'post',
        data,
      });
      other.downloadFile(response);
    },
    async exportById(ids: (string | number)[]): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysWechatUser/ExportExcelByIds',
        method: 'post',
        data: ids,
      });
      other.downloadFile(response);
    },
    async import(data: object): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysWechatUser/Import',
        method: 'post',
        data,
      });
    },
    async batchUnbind(ids: (string | number)[]): Promise<AxiosResponse> {
      return await request({
        url: '/api/syswechatuser/batchunbind',
        method: 'post',
        data: ids,
      });
    },

    async deleteUnboundUsers(): Promise<AxiosResponse<ISysWechatUserVm>> {
      return await request({
        url: '/api/SysWechatUser/DeleteUnboundUsers',
        method: 'post',
      });
    },

  };
}

export {SysWechatUserApi};

